home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #15
/
Monster Media Number 15 (Monster Media)(July 1996).ISO
/
prog_c
/
cuj0696.zip
/
DWYER.ZIP
/
FREQ.TST
/
README.FRQ
< prev
next >
Wrap
Text File
|
1995-12-29
|
8KB
|
250 lines
DESCRIPTION OF THE FREQUENCY TEST
Introduction
------------
Of the tests described in this article, the frequency test,
also called the equidistribution test by Knuth [K1, p. 59],
is the easiest to understand. What you do is grind out a
few hundred variates and check the see how uniformly they
are distributed. That isn't meant to imply that the variates
should occur with the same frequency because that wouldn't be
random behavior.
The frequency test is implemented as program freqtst. This
program provides two tests - a Kolmogorov-Smirnov (KS) test
and a chi-square test. Program freqtst gets its user-inputs
interactively - that is, from stdin. Alternatively, stdin
can be redirected to a file. Outputs are written to both
stderr and stdout - program prompts and error messages go
the stderr, results are written to stdout. The output to
stdout can be redirected to a file.
Running the Frequency Test
--------------------------
To start program freqtst, you can say simply
freqtst
and you will be prompted for the required inputs.
Alternatively, you can say
freqtst < [myfile.inp]
and the program will take its input data from myfile.inp.
The first two input parameters are:
o Seed for the random number generator (-1 = Time of day)
o Designation of generator to be tested
The third parameter specifies the test to be performed:
o C = Chi-square
o K = Kolmogorov-Smirnov
Remaining inputs depend on the choice of test. They are
described in the following sections. The KS test is
described first because techniques used there are
used in the chi-square test, too.
Kolmogorov-Smirnov Frequency Test
=================================
Purpose of Test (J.D.)
-----------------------
Other than to prove that the generator under
test is random, there must be some higher one
although I am unable at the moment to cobble
one up.
Description of Program Flow
---------------------------
There are two stages to the KS test sequence. In the first stage,
uniform variates are gathered, sorted and analyzed by a KS procedure
to yield two arrays of probabilities, P+ and P-. In the second stage,
these arrays are sorted and subjected to another KS procedure.
Outputs are two statistics, final Kn+ and Kn-, and corresponding
percentage points from the KS distribution function.
Invocation of Test
------------------
Start the program as described above. Your first two inputs
are seed and choice of generator. The third input must be "K"
to get you into the KS test procedure.
If you have your data stored in a file, you can redirect
the input unit to the file with
freqtst < [myfile.inp]
This file will look like this:
37417 # Starting Seed (-1 = time of day)
X # Generator Desired (X = Run-Time Lib rand)
K # Type of Test (K = Kolmogorov-Smirnov)
1024 # Number of Samples per Run
100 # Number Runs for K-S on K-S Test
Program Prompts and User Responses
----------------------------------
Program prompts (written to stderr) and result printouts
(written to stdout) will appear on your screen. Figure.1f
shows what freqtst writes to your screen. The data in the
figure.occurs when you redirect the input unit to a file
with the data shown above.
There are 41 lines in this printout with results mixed in
with command prompts. Picking out results can be a chore.
If you prefer to redirect the results written to stdout to
a disk file, you say:
freqtst < [myfile.inp] > [myfile.out]
Figure.2f shows what you'll see on your CRT and figure.3f
shows what you'll find in myfile.out.
Description of Algorithm
------------------------
The KS algorithm implemented in program freqtst is executed
in two source modules, ksfreq.c and execkosm.c:
1. ksfreq.c - Function KSFreq is called N times in
execkosm.c to produce N sets of KS statistics and
probabilities. N is the number of KS runs specified
by the user. Each set consists of four numbers - two
statistics K+ and K- and two probabilities P+ and P-.
The steps executed in this module, similar to those
given in [K1, pp. 48-49], are:
Step 1. Gather M uniform variates from the generator
specified by the user. Each variate is a 15-bit
integer. The number (M) of variates generated is
specified by the user as 'Samples per K-S Run' as
shown previously.
Step 2. Sort the M-array of variates in ascending order.
Step 3. Calculate K+ and K- as follows:
Let V[j] be the sorted array of uniform variates.
Then
K+ = max(j/M - V[j]/MAX_SAMPS), j=1,M
K- = max(V[j]/MAX_SAMPS - (j-1)/M), j=1,M
where MAX_SAMPS = 1 + MAX_RAND = 32768.
Calculations are performed in floating point type
double.
Function KSmirnov() is called to produce corresponding
probabilities:
P+ = KSmirnov(M, Kn+)
P- = KSmirnov(M, Kn-)
Because random deviates are stored as integers, function
KSCalc(), which processes an array of type double, is not
used.
Step 4. Output K+, P+, K-, P-
2. execkosm.c - This module applies the KS-on-KS portion of
this algorithm.
Step 1. Call function KSFreq() to produce KS probabilities.
This function implements the KS algorithm described
previously. These probabilities are stored in two
arrays. One is called PosProbAry; it holds the P+
probabilities. The other array is called NegProbAry;
it holds the P- probabilities. The number of times
that KSFreq is called to produce KS pairs is specified
by user as "K-S Runs For KS-on-KS Calculation."
Step 2. Sort each array in ascending order.
Step 3. Call function KSCalc() to calculate statistics
and probabilities for each array:
Let M be the number of pairs produced at Step 1.
o Get statistics and probabilities for P+:
KSCalc(PosProbAry, M, &KnPlusStat, &KnPlusProb,
&KnMinusStat, &KnMinusProb)
Print statistics and probabilities.
o Get statistics and probabilities for P-:
KSCalc(NegProbAry, M, &KnPlusStat, &KnPlusProb,
&KnMinusStat, &KnMinusProb)
Print statistics and probabilities.
Timing Estimates
----------------
The run described above required about 6.6 seconds on my
Pentium 100. Naturally, the time required depends on the
generator. For the data shown above, the range of times is
from 6.6 seconds for the MSC library function rand() to 7.3
seconds for the generator by Stephen L. Moshier.
Chi-Square Frequency Test
=========================
Description of Program Flow
---------------------------
There are two stages to the chi-square frequency test.
The first stage is devoted to generating and tallying
variates and calculating 100 chi-square probabilities.
The second stage consists of subjecting the resulting
array of probabilities to Kolmogorov-Smirnov analysis.
Output consists of Kolmogorov-Smirnov statistics and
probabilities as described previously.
Figure.4f shows a sample input file, figure.5f shows the
prompts and responses written to stderr and figure.6f
shows the results written to stdout.
The chi-square test procedure is implemented in two
modules, exchisq.c and chisqfrq.c. In the first stage,
module exchisq.c gets program control data, calculates
100 chi-square probabilities by calling ChiSqFreq() to
get statistics and function chdtr() to get probabilities.
In the second stage, function KSCalc() is called to
analyze the array of probabilities. This function
returns Kolmogorov statistics Kn+ and Kn- and their
corresponding probabilities P+ and P-. These data
are then printed.
Timing Estimates
----------------
The run shown in figure.4f required about 2.0 seconds on my
Pentium 100. Naturally, the time required depends on the
generator (and the CPU). For the data shown above, the range
of times is from 2.0 seconds for the MSC library function rand()
to 9.0 seconds for the generator by Stephen L. Moshier.